<?php
class Model_User_Mapper extends App_Model_Mapper
{
	protected $_map = array(
    	   'id'=>'id',
    	   'password'=>'password',
    	   'name'    => 'name',
           'surname' => 'surname',
           'fathername'=>'fathername',
           'size'      =>'size',
           'year'      =>'year',
           'email'     =>'email',
           'gender'    =>'gender',
	       'phone'     => 'phone'
	   );
	   
	   protected $_entityClass = 'Model_User';
	   protected function _setTable()
	   {
	   	return new Model_DbTable_User();
	   }

	   public function  authenticate($email, $password)
	   {
	    $db = Zend_Registry::get('db');
	    $authAdapter = new Zend_Auth_Adapter_DbTable($db);
	    $authAdapter->setTableName('user');
	    $authAdapter->setIdentityColumn($this->_map['email']);
	    $authAdapter->setCredentialColumn($this->_map['password']);
	    $authAdapter->setIdentity($email);
	    $authAdapter->setCredential(md5($password));
	    $auth = Zend_Auth::getInstance();
	    $result = $auth->authenticate($authAdapter);
	    if($result->isValid()){
	    	$data = $authAdapter->getResultRowObject(null, $this->_map['password']);
	    	$auth->getStorage()->write($data);
	    	return  true;
	    } else {
	    	return false;
	    }
	   }
}